package com.study.scapp.info.qingyun.controller;

import com.study.scapp.info.common.model.Response;
import com.study.scapp.info.qingyun.service.QingKeYunmpl;
import com.study.scapp.info.qingyun.service.RobotService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * @author 1
 * @data 2023/5/28
 */
@RestController
@RequestMapping("/qingYun")
public class QingYunController {



    public static final RobotService service = new QingKeYunmpl();

    /**
     * 调用青云Api
     * @param msg
     * @return
     */
    @GetMapping("/ke")
    public String qingYun(String msg){
        String s = "";
        String name = "";
        try {
                if ("886".equalsIgnoreCase(msg)){
                    System.out.println("欢迎下次使用，拜拜啦!");
                }else {
                    //调用青云api
                    Response response = service.AI(msg);
                    if (response != null && response.getResult() == 0){
                        //设置编码并从json中获取输出内容
                        s = new String(response.getContent().getBytes(), "UTF-8");
                        System.out.println(name+":"+s);
                        return s;
                    }else {
                        return "小助手还在学习中，暂时没明白您的意思，请重新输入。";
                    }
                }
            return s;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return s;
    }
}
